<template>
	<view>
    <view class="applyList">
      <view
        v-if="list.length==0"
        class="empty"
      >
        还没有任何相关申请
      </view>
      <view v-else>
        <view v-for="(item,index) in list" :key="index" class="apply-item">
          <view class="flex title">
            <view>{{ item.type=='bank'?'银行卡提现':'微信提现' }}</view>
            <view class="time"> {{item.createTime}}</view>
          </view>
          <view class="flex">
               <view class="apply-main">
                <view class="flex">

                    <view>{{JSON.parse(item.payeeInfo).account }}</view>
                    <view>{{ JSON.parse(item.payeeInfo).name }}</view>
                </view>
                <view class="flex" style="margin-bottom: 5rpx;">

                  <view>提现金额：{{ item.cashMoney }}</view>
                  <view>手续费：{{ item.commissionMoney }}</view>
                </view>
                <view v-if="item.state==2" style="color:red;">
                  驳回原因：{{item.rejectReason}}
                </view>
              </view>
              <view>
                <span v-if="item.state==5" class="bnt" @tap="open(item.id)">上传发票</span>
                <span v-if="item.state==2" style="color: red;">已驳回</span>
                <span v-if="item.state==1" style="color: #3a86b9;">已通过</span>
                <span v-if="item.state==0 ||item.state==3 ||item.state==4   " style="color: #ff0000;">审核中</span>
              </view>
          </view>
        </view>
      </view>
    </view>
    <view class="popup" v-if="popupShow">
      <view class="mask"></view>
      <view class="popup-item">
        <view class="popup-tit">上传发票：</view>
        <view class="inputView">
          <view class="bg-img" v-if="img" style="width: 200rpx;height: 200rpx;">
            <image :src='img' mode='aspectFill' style="width: 100%;height: 100%;"></image>
            <view class="cu-tag bg-red" @tap="deleteImage" :data-index="index">
               <uni-icons type="clear" size="20" color="red"></uni-icons>
            </view>
          </view>
          <view class="solids" @tap="ChooseImage" v-if="img==''">
            <view class="scam">
 <uni-icons type="camera" size="50"  color="#eee"></uni-icons>
            </view>
          </view>
        </view>
        <view class="handle">
          <view @tap="cancel">取消</view>
          <view @tap="upSupport" style="background-color: #3a86b9;color: #fff;">确定</view>
        </view>
      </view>
    </view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
 const picUrl = import.meta.env.VITE_APP_RESOURCES_URL
 const baseUrl = import.meta.env.VITE_APP_BASE_API
	const list=ref([])
  const current = ref(1)
  const pages = ref(0)
  const popupShow=ref(false)
  const Oid = ref('')
   const img=ref('')
  onLoad(() => {
    getlist(current.value)
  })
  onReachBottom(() => {
    if (current.value < pages.value) {
      getlist( current.value + 1)
    }
  })
  const open=(id)=>{
      Oid.value=id
      popupShow.value=true

      console.log(Oid.value)
  }
  const cancel=()=>{
      popupShow.value=false

  }
  const deleteImage=()=>{
    img.value=''
  }
  const upSupport=()=>{
    if(img.value==''){
      uni.showToast({
        title:"请先上传图片"
      })
      return
    }
    uni.showLoading()
    http.request({
      url: '/p/user/cashOut',
      method: 'PUT',
      data: {
          id: Oid.value,
          invoiceImgs: img.value,
          state: 3,
          invoiceRejectReason: ""
      }
    })
     .then(({ data }) => {
        uni.hideLoading()
        if(data==true)
        uni.showToast({
          title:"上传成功"
        })
         popupShow.value=false
         current.value=1
         getlist(current.value)
      })
  }
  const ChooseImage=(e)=>{
    let token=uni.getStorageSync('Token')
      wx.chooseImage({
        count: 1, //默认9
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album'], //从相册选择
        success: (res) => {
          console.log(res);
           uni.uploadFile({
            //url:"http://192.168.1.5:8080/file/upload",
            //url:"https://zhwy.pengyuevip.com/gateway/file/upload",
             url:baseUrl + "/user/file/upload/element",
             filePath:res.tempFilePaths[0],
             name:'file',
             header: { 'Authorization': 'Bearer '+   token },
             success(res) {
               console.log(res)
               let url=JSON.parse(res.data).data;
               img.value=picUrl +url;
             }
           })
        }
      });
    }
  const getlist = (currentParam) => {
    uni.showLoading()
    http.request({
      url: '/p/user/cashOut/page',
      method: 'GET',
      data: {
        current: currentParam,
        size: 10,
      }
    })
      .then(({ data }) => {
        let listParam = []
        if (data.current === 1) {
          listParam = data.records
        } else {
          listParam = list.value
          Array.prototype.push.apply(listParam, data.records)
        }
        list.value = listParam
        pages.value = data.pages
        current.value = data.current
        uni.hideLoading()
        console.log(list.value)
      })
  }
</script>
<style  scoped lang="scss">
  @use './cash.scss';

</style>
